import datetime, time


def cacular_date(date_, day_):
    if isinstance(date_, datetime.date):
        date_ = date_.strftime("%Y-%m-%d")
    if day_ > 0:
        day_ = day_ - 1
    return (datetime.datetime.strptime(date_, "%Y-%m-%d")
            + datetime.timedelta(days=day_)).strftime("%Y-%m-%d")


def getEveryDay(begin_date,end_date):
    # 前闭后闭
    date_list = []
    if isinstance(begin_date, datetime.date):
        begin_date = begin_date.strftime('%Y-%m-%d')
    if isinstance(end_date, datetime.date):
        end_date = end_date.strftime('%Y-%m-%d')
    if isinstance(begin_date, str):
        begin_date = datetime.datetime.strptime(begin_date, "%Y-%m-%d")
    if isinstance(end_date, str):
        end_date = datetime.datetime.strptime(end_date,"%Y-%m-%d")
    while begin_date <= end_date:
        date_str = begin_date.strftime("%Y-%m-%d")
        date_list.append(date_str)
        begin_date += datetime.timedelta(days=1)
    return date_list

def hriline_2_slash(date_):
    date_ = datetime.datetime.strptime(date_, "%Y-%m-%d")
    date_ = datetime.datetime.strftime(date_, "%Y/%m/%d")
    return date_


def tranfer_timer(timestamp):
    time_local = time.localtime(timestamp)
    # 转换成新的时间格式(2016-05-05 20:28:54)
    dt = time.strftime("%Y-%m-%d", time_local)
    return dt
